package scripts;
import bot.ScriptMethods;

public class EndlessFlax extends ScriptMethods implements Runnable {

	public void start() {
		System.gc();
		getAccountSettings();

		scriptRunning = true;
		scriptThread = new Thread(this);
		scriptThread.start();
	}

	public void stop() {
		System.gc();
		scriptThread = null;
		scriptRunning = false;
		debug("Stopped script.");
	}

	public void run() {
		while (scriptRunning) {
			try {
				handleEvents();

				int[] spinningwheel = getObjectById(121);
				if (ourPlayerY() < 999) {
					if (getInventorySize() == 30) {
						atObject(692, 525);
						wait(2000);
					}

					if (getInventorySize() != 30) {
						atObject2(693, 524);
						wait(610);
					}
				}

				if (ourPlayerY() > 999) {

					if (invContains(675)) {
						useItemOnObject(spinningwheel[1], spinningwheel[2], 675);
						wait(610);
					}

					if (invContains(676)) {
						dropItem(676);
						wait(610);
					}

					if (getInventorySize() < 3) {
						atObject(692, 1469);
						wait(2000);
					}
				}

				wait(random(50, 80));
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	public void handleEvents() throws Exception {
		if (getFatigue() > 80 && !isSleeping()) {
			wait(600);
			useItem(1263);
			wait(600);
		}
		if (welcomeBoxOpen())
			setWelcomeBox();
		if (!isLoggedIn())
			doLogin();
		if (getFatigueSleeping() < 10 && isSleeping())
			doSleeping();
	}
}